<?php

namespace app\services\base;

trait Error
{
    public static $errors = [];

    public static function addError($errors)
    {
        if (is_array($errors)) {
            self::$errors = array_merge(self::$errors, $errors);
        } else {
            array_push(self::$errors, $errors);
        }
    }

    public static function getErrors()
    {
        return self::$errors;
    }

    public static function getLastError()
    {
        if (count(self::$errors) > 0) {
            return end(self::$errors);
        }

        return null;
    }
}